package org.dealpdf.sample;

import org.dealpdf.model.ContainmentMeasure;
import org.dealpdf.model.OutboundDetail;
import org.dealpdf.model.ProblemMap;
import org.dealpdf.model.TemporaryMeasure;
import org.dealpdf.utils.ExcelUtil;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ExportExcelGenerator {
     public static void main(String[] args) {
            try {
                // Excel 处理
                generate8DExcel();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    private static void generate8DExcel() throws IOException {
        String templatePath = "src/main/resources/8DTemplate.xlsx";
        String outputPath = "8DOutput.xlsx";

        // 准备数据
        Map<String, String> problemData = getProblemMap();
        ProblemMap problemMap = new ProblemMap(problemData);
        List<ContainmentMeasure> containmentMeasures = getContainmentMeasures();
        List<TemporaryMeasure> temporaryMeasures = getTemporaryMeasures();

        // 生成 Excel
        ExcelUtil.generate8DExcel(templatePath, outputPath, problemMap, containmentMeasures, temporaryMeasures);
    }


    private static List<OutboundDetail> generateSampleDetails() {
        List<OutboundDetail> details = new ArrayList<>();
        details.add(new OutboundDetail("BF-03-05-1", "no1", "34CrNiMo6", "原材料", 6.60, 100.00));
        details.add(new OutboundDetail("BF-03-05-2", "no2", "35CrMo", "半成品", 5.5, 120.00));
        details.add(new OutboundDetail("BF-03-05-3", "no3", "Q235", "成品", 10.0, 80.00));
        return details;
    }

    private static Map<String, String> getProblemMap() {
        Map<String, String> problemMap = new HashMap<>();
        problemMap.put("problem_title", "发动机故障");
        problemMap.put("jira_code", "JIRA-12345");
        problemMap.put("happen_place", "生产线A");
        problemMap.put("happen_date", "2025-07-10");
        problemMap.put("charge_person_name", "张三");
        problemMap.put("charge_person_dept_name", "工程部");
        problemMap.put("launch_person_name", "李四");
        problemMap.put("launch_person_dept_name", "质量部");
        problemMap.put("create_time", "2025-07-11 09:00");
        problemMap.put("problem_code", "8D-001");
        problemMap.put("problem_source", "客户反馈");
        problemMap.put("severity", "高");
        problemMap.put("occurrence_frequency", "3次");
        problemMap.put("vin", "VIN123456789");
        problemMap.put("part_serial_number", "SN-001");
        problemMap.put("software_baseline", "V1.0");
        problemMap.put("hardware_version", "HW-1.2");
        problemMap.put("instrument_fault_warning", "发动机警告");
        problemMap.put("supplier_name", "供应商A");
        problemMap.put("project_name", "项目X");
        problemMap.put("who", "李四");
        problemMap.put("what", "发动机");
        problemMap.put("where_place", "生产线A");
        problemMap.put("when_time", "2025-07-10 14:00");
        problemMap.put("amount", "5000元");
        return problemMap;
    }

    private static List<ContainmentMeasure> getContainmentMeasures() {
        List<ContainmentMeasure> measures = new ArrayList<>();
        for (int i = 1; i <= 10; i++) {
            measures.add(new ContainmentMeasure(
                    "围堵措施 " + i,
                    "2025-07-11",
                    "2025-07-15",
                    "有效"
            ));
        }
        return measures;
    }

    private static List<TemporaryMeasure> getTemporaryMeasures() {
        List<TemporaryMeasure> tempMeasures = new ArrayList<>();
        for (int i = 1; i <= 10; i++) {
            tempMeasures.add(new TemporaryMeasure(
                    "临时措施 " + i,
                    "2025-07-12",
                    "2025-07-13",
                    "2025-07-14",
                    "2025-07-16",
                    "有效"
            ));
        }
        return tempMeasures;
    }

    }